package com.acorn.community.common.exception;


import com.acorn.community.common.api.Resp;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常捕获
 *
 * @author tianshiwei
 */
@ControllerAdvice
public class GlobalExceptionHandler {


    /**
     * 业务异常捕获
     *
     * @param ex
     * @return
     */
    @ResponseBody
    @ExceptionHandler(value = BusinessException.class)
    public Resp BusinessExceptionHandle(BusinessException ex) {
        return Resp.error(ex.getCode(), ex.getMessage());
    }

    /**
     * 业务异常处理
     *
     * @return 异常返回结果
     */
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Resp exceptionHandle(Exception ex) {
        return Resp.error(CodeMsg.ERROR);
    }
}